package com.fh.fruit.service.activity.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.fh.dao.DaoSupport;
import com.fh.entity.Page;
import com.fh.fruit.entity.activity.ActivityRule;
import com.fh.fruit.entity.activity.ActivityRuleType;
import com.fh.fruit.service.activity.ActivityRuleManager;
import com.fh.fruit.service.activity.ActivityRuleTypeManager;
import com.fh.util.PageData;

/**
 *活动规则
 * 
 * @author Administrator
 * @version 2017.11.30 15:39
 */
@Service("activityRuleTypeService")
public class ActivityRuleTypeService implements ActivityRuleTypeManager {
	@Resource(name = "daoSupport")
	private DaoSupport dao;

	/**
	 * 获取活动规则分类
	* @author 葛欢欢
	* @version 2017.11.30 16:40 
	* @return
	* @throws Exception
	 */
	public List<ActivityRuleType> getActivityRuleType(Page page) throws Exception {
		// TODO Auto-generated method stub
		return (List<ActivityRuleType>) dao.findForList("ActivityRuleTypeManager.getActivityRuleType",page);
	}

	/**
	  * 添加活动规则分类
	 * @author 葛欢欢
	 * @version 2017.11.30 16:40 
	 * @param ActivityRuleType
	 * @return
	 * @throws Exception 
	  */
	public int addActivityRuleType(PageData pd) throws Exception {
		// TODO Auto-generated method stub
		ActivityRuleType activityRuleType = new ActivityRuleType();
		activityRuleType.setActivityId(Integer.parseInt(pd.getString("activityId")));
		activityRuleType.setName(pd.getString("name"));
		activityRuleType.setCreateId(pd.getString("createId"));
		activityRuleType.setCreateTime(pd.getString("createTime"));
		return (int) dao.save("ActivityRuleTypeManager.addActivityRuleType", activityRuleType);
	}

	/**
	  * 修改活动规则分类
	 * @author 葛欢欢
	 * @version 2017.11.30 16:40 
	 * @param ActivityRuleType
	 * @return
	 * @throws Exception
	  */
	public int updateActivityRuleType(PageData pd) throws Exception {
		// TODO Auto-generated method stub
		ActivityRuleType activityRuleType = new ActivityRuleType();
		activityRuleType.setId(Integer.parseInt(pd.getString("id")));
		activityRuleType.setActivityId(Integer.parseInt(pd.getString("activityId")));
		activityRuleType.setName(pd.getString("name"));
		activityRuleType.setUpdateId(pd.getString("updateId"));
		activityRuleType.setUpdateTime(pd.getString("updateTime"));
		activityRuleType.setCreateId(pd.getString("createId"));
		activityRuleType.setCreateTime(pd.getString("createTime"));
		return (int) dao.update("ActivityRuleTypeManager.updateActivityRuleType", activityRuleType);
	}

	/**
	  * 删除活动规则分类
	 * @author 葛欢欢
	 * @version 2017.11.30 16:40 
	 * @param id
	 * @return
	 * @throws Exception
	  */
	public int deleteActivityRuleType(int id) throws Exception {
		// TODO Auto-generated method stub
		return (int) dao.delete("ActivityRuleTypeManager.deleteActivityRuleType", id);
	}

	@Override
	public ActivityRuleType getActivityRuleTypeById(int id) throws Exception {
		// TODO Auto-generated method stub
		return (ActivityRuleType) dao.findForObject("ActivityRuleTypeManager.getActivityRuleTypeById", id);
	}

	
}
